package view;

import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

public abstract class AbstractCrudView<E> extends FFDialog {

	private static final long serialVersionUID = -598415693608307445L;
	
	protected JPanel contentPanel;
	protected JTextField txtLocalizar;

	protected JButton btnLocalizar;

	protected JButton btnInserir;

	protected JButton btnAlterar;

	protected JButton btnDeletar;
	protected JTable table;
	protected DefaultTableModel dtm;

	/**
	 * Create the dialog.
	 */
	public AbstractCrudView(JFrame principal, String caption, boolean modal) {
		super(principal, caption, modal);
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FIXME tirar em todos os JDialog
		setBounds(100, 100, 1050, 445);
		contentPanel = new JPanel();
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPanel);
		contentPanel.setLayout(null);
		
		JLabel lblBusca = new JLabel("Busca:");
		lblBusca.setBounds(10, 11, 46, 14);
		contentPanel.add(lblBusca);
		
		txtLocalizar = new JTextField();
		txtLocalizar.setBounds(50, 8, 277, 20);
		contentPanel.add(txtLocalizar);
		txtLocalizar.setColumns(10);
		
		btnLocalizar = new JButton("Localizar");
		btnLocalizar.setBounds(348, 7, 89, 23);
		contentPanel.add(btnLocalizar);
		btnLocalizar.setMnemonic('L');
		btnLocalizar.addActionListener( getActionBtnLocalizar() );
		
		btnInserir = new JButton("Inserir");
		btnInserir.setBounds(10, 354, 89, 23);
		contentPanel.add(btnInserir);
		btnInserir.addActionListener( getActionBtnInserir() );
		
		btnAlterar = new JButton("Alterar");
		btnAlterar.setBounds(120, 354, 89, 23);
		contentPanel.add(btnAlterar);
		btnAlterar.addActionListener( getActionBtnAlterar() );
		
		btnDeletar = new JButton("Deletar");
		btnDeletar.setBounds(238, 354, 89, 23);
		contentPanel.add(btnDeletar);
		btnDeletar.addActionListener( getActionBtnDeletar() );
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 39, 771, 304);
		contentPanel.add(scrollPane);
		
		table = new JTable( getDefaultTableModel() );
		scrollPane.setViewportView(table);
	}
	
	public abstract DefaultTableModel getDefaultTableModel();
	
	public abstract ActionListener getActionBtnLocalizar();
	
	public abstract ActionListener getActionBtnInserir();
	
	public abstract ActionListener getActionBtnAlterar();
	
	public abstract ActionListener getActionBtnDeletar();
	
	public abstract void populateGrid(List<E> dados);
	
}
